<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>location.hash跨域</title>
</head>
<body>
<p>hello world</p>
<script>
var p = document.getElementsByTagName('p')[0];
var iframe = document.createElement('iframe');
iframe.src = 'http://localhost:3001/c.html#getdata';   // location.hash为'#getdata'
iframe.style.display = 'none';
document.body.appendChild(iframe);

function checkHash () {
    if (location.hash) {
        let data = location.hash.substring(1);     // 去除'#'号
        p.innerHTML = data;
    }
}
setInterval(checkHash, 2000);   // 每隔2s监听hash值是否发生变化
</script>
</body>
</html>